package com.raven.craft.code.generator.mysql.schema.md;

import com.raven.craft.code.generator.IGenerator;
import com.raven.craft.code.generator.common.constant.FileSuffix;
import com.raven.craft.code.generator.common.file.HbsFile;
import com.raven.craft.code.generator.common.file.metadata.FileMetadata;
import com.raven.craft.code.generator.config.MysqlContext;
import lombok.extern.slf4j.Slf4j;

/**
 * @author raven
 * @date 2020/08/25
 **/
@Slf4j
public class MdSchemaGenerator implements IGenerator {

    private final MysqlContext context;
    private final MdSchemaProperties properties;

    public MdSchemaGenerator(MysqlContext context, MdSchemaProperties properties) {
        this.context = context;
        this.properties = properties;
    }

    @Override
    public void generate() {
        log.info("begin to generate markdown schema file");
        createMdSchemaFile(context, properties).output();
    }

    public HbsFile createMdSchemaFile(MysqlContext context, MdSchemaProperties properties) {
        FileMetadata metadata = new FileMetadata(context.getDatabase(), FileSuffix.MARKDOWN, properties.getTargetDir());
        MdSchemaVo vo = new MdSchemaVo(context, properties);
        return new HbsFile(metadata, properties.getTemplatePath(), vo);
    }
}
